import md5 from "./md5.js";

const install = (Vue, vm) => {
	let timer
	Vue.prototype.$t = {
		toUpperCase(arg) {
			return arg && arg.toUpperCase();
		},
		isMobile(arg) {
			return /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(arg);
		},

		md5(arg) {
			debugger
			return md5.hex_md5(arg);
		},
		/**
		 * 防抖-执行fn
		 * @param {Object} fn 方法函数
		 * @param {Object} wait 默认500毫秒内只执行最后一次
		 */
		fd(fn, wait) {
			let delay = wait || 500
			if (timer) {
				clearTimeout(timer)
				console.log('拦截')
			}
			timer = setTimeout(() => {
				console.log('发送')
				timer = null
				typeof fn === 'function' && fn()
			}, delay)
		},
		unit(type) {
			if (type == 1) {
				return '盒';
			} else if (type == 2) {
				return '斤';
			} else if (type == 3) {
				return '袋';
			} else {
				return '件';
			}
		},
	}
}

export default {
	install
}
